home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-05 | 1.5 KB | 63 lines | [TEXT/MMCC] |
-
- // * Comment Tzu
- // * ©1994 Chris K. Thomas. All Rights Reserved.
- // *
- // * 100 11 Oct 94 ckt
- // * 101 13 Oct 94 ckt - rewrote to comment more intelligently
- // * & wrote InsertText & comment
-
- #include "TzuTools.h"
-
- pascal void main(Handle text);
- void InsertText(Handle hText,long insertOffset,long insertLen,const void *insert);
-
- // * Main entry point
- // text - handle to text to be modified
- pascal void main(Handle text)
- {
- EnterCodeResource();
-
- const char *commentText = "//";
- long sizeOfText = GetHandleSize(text);
- Ptr localText = *text;
-
- // insert “//” before text, since there isn't a return there usually
- InsertText(text,0,2,commentText);
-
- // replace returns with return + “//”
- for(long i=0; i<(sizeOfText-1); i++)
- {
- localText = *text;
- if(localText[i]=='\r')
- {
- InsertText(text,i+1,2,commentText);
- i+=1;
- }
- }
-
- ExitCodeResource();
- }
-
-
- //InsertText will probably be a callback in the
- //robustified TzuTool interface
- void InsertText(Handle hText,long insertOffset,long insertLen,const void *insert)
- {
- long hTextLen = GetHandleSize(hText);
- char hTextState = HGetState(hText);
- Ptr localText = NULL;
-
- // SetHandleSize might need to move the memory to resize it
- // which it can't do if the handle is locked
- HUnlock(hText);
- SetHandleSize(hText,hTextLen + insertLen);
- if(MemError()!=noErr) return;
-
- HLockHi(hText);
- localText = *hText;
-
- BlockMoveData(&localText[insertOffset],&localText[insertOffset+insertLen],hTextLen - insertOffset);
- BlockMoveData(insert,&localText[insertOffset],insertLen);
-
- HSetState(hText,hTextState);
- }